package com.linyaonan.leetcode.easy._232;

import java.util.Stack;

class MyQueue {
    Stack<Integer> queue;
    Stack<Integer> tmp;
    /** Initialize your data structure here. */
    public MyQueue() {
        queue = new Stack<>();
        tmp = new Stack<>();
    }
    
    /** Push element x to the back of queue. */
    public void push(int x) {
        this.queue.push(x);
    }
    
    /** Removes the element from in front of queue and returns that element. */
    public int pop() {
        while (!queue.empty()) {
            tmp.push(queue.pop());
        }
        int r = tmp.pop();
        while (!tmp.empty()) {
            queue.push(tmp.pop());
        }
        return r;
    }
    
    /** Get the front element. */
    public int peek() {
        while (!queue.empty()) {
            tmp.push(queue.pop());
        }
        int r = tmp.peek();
        while (!tmp.empty()) {
            queue.push(tmp.pop());
        }
        return r;
    }
    
    /** Returns whether the queue is empty. */
    public boolean empty() {
        return this.queue.isEmpty();
    }
}